import jionlp as jio
import json
import demjson
import os, re;

"""
标注0
分得   
扣押


标注1
认定取值


"""
if __name__ == '__main__':
    with open("/Users/wengjunjie/works/ai-nlp/11data/1632652927949/train", "r") as f:
        i = 0
        true_num = 0
        for line in f.readlines():
            line = line.strip('\n')  # 去掉列表中每一个元素的换行符
            data2 = json.loads(line)

            if data2.get("money") == '800.0':
                print("aa")
            data2.get("filename")
            ##另查明, 是另外一件事情
            justice = data2.get("justice").split('另查明')[0]
            justice = justice.replace('余元', '元').replace('(', '').replace(')', '')
            moneys = jio.extract_money(justice)
            standard_moneys = [jio.money_standardization(i) for i in moneys]
            pre_money = 0
            for money in standard_moneys:
                if money == 'null':
                    justice = justice.replace('余万元', '万元')
                    break
                    ##0元，说明预测有问题

            pattern = r'[，|。]'
            justice = re.split(pattern, justice)
            justice_res = ""
            justice_heji = ""
            for justiceTmp in justice:
                if '分得' in justiceTmp:
                    i = i + 0
                elif '合计人民币' in justiceTmp:
                    justice_heji = justice_heji + justiceTmp
                elif '总计' in justiceTmp and '元' in justiceTmp:
                    justice_res = justiceTmp
                    break
                elif '全部' in justiceTmp and '元' in justiceTmp:
                    justice_res = justiceTmp
                    break
                elif '共计' in justiceTmp and '元' in justiceTmp:
                    justice_res = justiceTmp
                    break
                else:
                    justice_res = justice_res + justiceTmp
            # 说明已经有合计，有法官汇总好的数据
            if justice_heji != '':
                justice_res = justice_heji
            moneys = jio.extract_money(justice_res)
            standard_moneys = [jio.money_standardization(i) for i in moneys]
            pre_money = 0
            for money in standard_moneys:
                if money == 'null':
                    money = '0'
                pre_money += float(money.replace("元", ""))
            print(standard_moneys)
            if pre_money == 0:
                print("xxxx=0")
            if float(data2.get("money")) == pre_money:
                true_num += 1
            else:
                print(i, "....", data2.get("money"), pre_money, line)
            i = i + 1
    print(true_num, i, true_num * 1.0 / i)

# https://www.zhihu.com/question/438415428/answer/1667163390
